"""
mongo demo
"""

import pymongo
from pymongo import *
import LogMgr

mongoUrl = 'mongodb://gps:gps@192.168.1.62/?authSource=gps'
dbName = 'gps'
logger = LogMgr.getLogger('mongo')

def showVersion():
    print(dir(pymongo))
    print(pymongo.__version__)

def query_one():
    client = MongoClient(mongoUrl)
    db = client[dbName]
    print(repr(db))
    collection = db['curgps']
    return collection.find_one()

def query_all():
    client = MongoClient(mongoUrl)
    db = client[dbName]
    #print repr(db)
    collection = db['curgps']
    cursor = collection.find(projection={'_id': False, 'devid': True, 'hostid':True})
    for obj in cursor:
        print(obj)
        #logger.info(obj)

def export():
    client = MongoClient(mongoUrl)
    db = client[dbName]

if __name__ == "__main__":
    query_all()
